package com.synchrona.replySyncManager;

import java.util.ArrayList;
import java.util.List;

import com.synchrona.account.Account;
import com.synchrona.dataProcessor.DataProcessor;
import com.synchrona.pluginManager.PluginManager;
import com.synchrona.syncDataAccess.SyncDataAccess;
import com.synchrona.update.Update;
import com.synchrona.updateSyncManager.UpdateProcessor;
import com.synchrona.user.User;

public class ReplySyncManager {

	
	public ReplySyncManager(){
		
	}
	
	public void getReplies(Update update){
		try {
			DataProcessor processor = new DataProcessor(update);
			update = processor.process();
			User user = (User)update.getUser();
			String userName = user.getUserName();
			System.out.println(userName);
			user = getUser(userName);
			PluginManager manager = new PluginManager();
			manager.getComments(user);
			
		} catch (Exception e) {
			e.printStackTrace();
		}
	}
	
	// /Returns the user on the user name
	public User getUser(String userName) {
		User user = new User();
		SyncDataAccess access = new SyncDataAccess();
		try {
			user = access.getUser(userName);
			if (user != null) {
				List<Account> accountList = new ArrayList<Account>();
				accountList = getUserAccounts((int) user.getUserId());
				user.setAccountList(accountList);
			}
		} catch (Exception e) {
			e.printStackTrace();
		}
		return user;
	}
	
	// Returns the user account lists
	public List<Account> getUserAccounts(int userId) {
		List<Account> userAccounts = new ArrayList<Account>();
		try {
			SyncDataAccess access = new SyncDataAccess();
			userAccounts = access.getUserAccounts(userId);
		} catch (Exception e) {
			e.printStackTrace();
		}
		return userAccounts;
	}
}
